/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import dayjs from 'dayjs'

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
const DATE_FORMAT = 'YYYY-MM-DD'

export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
  return dayjs(date).format(format)
}

export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string {
  return dayjs(date).format(format)
}
export function getHourMins(timestamp: number, str=''): string {
  let date = new Date(timestamp);
  let hours = date.getHours();
  let minutes = date.getMinutes();
  return hours + str + minutes;
}
export function unique(arr,name){
  const uniqueArr = arr.filter((item,index) => arr.findIndex(obj => obj[name] === item[name]) === index );
  return uniqueArr
}
export const dateUtil = dayjs
